﻿using Microsoft.Xna.Framework;

namespace ADiKt {
    class MainMenuScreen : MenuScreen {
        /// <summary> the main screen you see upon atarting the game </summary>
        public MainMenuScreen() : base("Main Menu") {
            // Create our menu entries.
            MenuEntry playGameMenuEntry = new MenuEntry("Start game"); 
            MenuEntry setupMenuEntry = new MenuEntry("Lines Setup");
            MenuEntry optionsMenuEntry = new MenuEntry("Options");
            MenuEntry exitMenuEntry = new MenuEntry("Exit");

            // Hook up menu event handlers.
            playGameMenuEntry.Selected += PlayGameMenuEntrySelected;
            setupMenuEntry.Selected += setupMenuEntrySelected;
            optionsMenuEntry.Selected += OptionsMenuEntrySelected;
            exitMenuEntry.Selected += OnCancel;

            // Add entries to the menu.
            MenuEntries.Add(playGameMenuEntry);
            MenuEntries.Add(setupMenuEntry);
            MenuEntries.Add(optionsMenuEntry);
            MenuEntries.Add(exitMenuEntry);
        }

        void setupMenuEntrySelected(object sender, PlayerIndexEventArgs e) {
            ScreenManager.AddScreen(new SetupScreen(), e.PlayerIndex);
        }

        void PlayGameMenuEntrySelected(object sender, PlayerIndexEventArgs e) {
            LoadingScreen.Load(ScreenManager, true, e.PlayerIndex, new GameplayScreen());
        }

        void OptionsMenuEntrySelected(object sender, PlayerIndexEventArgs e) {
            ScreenManager.AddScreen(new OptionsMenuScreen(), e.PlayerIndex);
        }

        protected override void OnCancel(PlayerIndex playerIndex) {
            const string message = "Are you sure you want to exit?";
            MessageBoxScreen confirmExitMessageBox = new MessageBoxScreen(message, true);
            confirmExitMessageBox.Accepted += ConfirmExitMessageBoxAccepted;
            ScreenManager.AddScreen(confirmExitMessageBox, playerIndex);
        }

        void ConfirmExitMessageBoxAccepted(object sender, PlayerIndexEventArgs e) {
            ScreenManager.Game.Exit();
        }
    }
}
